package offer;

public class offer_0026 {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if(A==null||B==null) return false;
        return search(A,B);
    }
    public boolean search(TreeNode a,TreeNode b){
        if(a==null&&b!=null) return false;
        if(b==null) return true;
        if(a.val== b.val){
             return forcesearch(a,b)||search(a.left,b)||search(a.right,b);
        }
        return search(a.left,b)||search(a.right,b);
    }
    public boolean forcesearch(TreeNode a,TreeNode b){
        if(a==null&&b!=null) return false;
        if(b==null) return true;
        if(a.val!= b.val) return false;
        return forcesearch(a.left,b.left)&&forcesearch(a.right,b.right);
    }
}
